//
//  PaiHangCell.m
//  代号：47
//
//  Created by 杨佩璋 on 15/7/6.
//  Copyright (c) 2015年 杨佩璋. All rights reserved.
//

#import "PaiHangCell.h"
#import <UIImageView+WebCache.h>


@implementation PaiHangCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    CGFloat w = 0.25 *kScreen_width ;
    if ( self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        _postImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 0.25 *kScreen_width, 1481 *0.25*kScreen_width /1000)];
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(20 + w, 10, kScreen_width - 20 - w - 10, 40)];
        _contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(20 + w, 50+10, kScreen_width - 20 - w - 10, 0)];
        
        _nameLabel.font = [UIFont boldSystemFontOfSize:14];
        _contentLabel.font = [UIFont systemFontOfSize:12];
        _contentLabel.numberOfLines = 0;
        
        
        [self.contentView addSubview:self.postImage];
        [self.contentView addSubview:self.nameLabel];
        [self.contentView addSubview:self.contentLabel];
        
        [_postImage release];
        [_nameLabel release];
        [_contentLabel release];
        
    }
    return self;
}

- (void)setModel:(PaiHangModel *)model{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    [_postImage sd_setImageWithURL:[NSURL URLWithString:model.posterUrl]];
    _nameLabel.text = model.name;
    _contentLabel.text = model.remark;
    _contentLabel.height = [PaiHangCell heightForStr:model.remark];
    
}

+ (CGFloat)heightForStr:(NSString *)str{
    CGFloat w = 0.25 *kScreen_width ;
  CGRect rect =  [str boundingRectWithSize:CGSizeMake(kScreen_width - 20 - w - 10, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]} context:nil];
    return rect.size.height;
}

+(CGFloat)heightForCell:(PaiHangModel *)model{
    return (1481 *0.25*kScreen_width /1000 + 10) >( 60 + [PaiHangCell heightForStr:model.remark] ) ? (1481 *0.25*kScreen_width /1000 + 10) + 10 :  ( 60 + [PaiHangCell heightForStr:model.remark] ) + 10;
}



-(void)dealloc{
    [_model release];
    [super dealloc];
}

@end
